*** The school-type gap, Table 11

clear
use "${data}cleaned_data_y3.dta"
do "${blocks}construct_new_variables"

gen type_state_school=1 if SchoolType=="Maintained" & DomicileCat=="Home" & WinterPool==0
replace type_state_school=2 if SchoolType=="Independent" & DomicileCat=="Home" & WinterPool==1

label define school 1 "Direct state-funded"  2 "Pooled privately-funded"
label values type_state_school school

********************************************************************************
*
*                              FIRST YEAR
*
********************************************************************************

ttest std_perc_y1, by(type_state_school)

quietly: reg std_perc_y1 ib1.type_state_school, vce(cluster ApplyCollege)
onesided 2.type_state_school
estadd local course_fe ""
estadd local apply_college_fe ""
eststo r1

reg std_perc_y1 ib1.type_state_school i.Course i.ApplyCollege, vce(robust)
onesided 2.type_state_school
estadd local course_fe "\checkmark"
estadd local apply_college_fe "\checkmark"
eststo r2

* Split by subject

log using "${temp}school_by_subject", replace

areg std_perc_y1 ib1.type_state_school i.Course if EEMP==1, a(ApplyCollege) vce(robust)
onesided 2.type_state_school
estadd local course_fe "\checkmark"
estadd local apply_college_fe "\checkmark"
eststo r3

areg std_perc_y1 ib1.type_state_school i.Course if EEMP==0, a(ApplyCollege) vce(robust)
onesided 2.type_state_school
estadd local course_fe "\checkmark"
estadd local apply_college_fe "\checkmark"
eststo r4
log close

********************************************************************************
*
*                              LATER YEARS
*
********************************************************************************

egen mean_perc_y2 = mean(Percentage_y2), by(Course)
egen sd_perc_y2   = sd(Percentage_y2), by(Course)
gen std_perc_y2   = (Percentage_y2 - mean_perc_y2) / sd_perc_y2

reg std_perc_y2 ib1.type_state_school i.Course i.ApplyCollege, vce(robust)
onesided 2.type_state_school
estadd local course_fe "\checkmark"
estadd local apply_college_fe "\checkmark"
eststo r5

egen mean_perc_y3 = mean(Percentage_y3), by(Course)
egen sd_perc_y3   = sd(Percentage_y3), by(Course)
gen std_perc_y3   = (Percentage_y3 - mean_perc_y3) / sd_perc_y3

reg std_perc_y3 ib1.type_state_school i.Course i.ApplyCollege, vce(robust)
onesided 2.type_state_school
estadd local course_fe "\checkmark"
estadd local apply_college_fe "\checkmark"
eststo r6

esttab r1 r2 r3 r4 r5 r6 using "${tables}school.tex", cells(b(pval(pval) fmt(2)) se(par fmt(2))) keep(2.type_state_school) collabels(none) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("course_fe Subject FE" ///
"apply_college_fe Application college FE ") ///
eqlabels(none) label varwidth(25) posthead(" & \multicolumn{2}{c}{All subjects} & \multicolumn{1}{c}{Non-MI} & \multicolumn{1}{c}{MI} & \multicolumn{2}{c}{All subjects} \\" ///
" \cmidrule(lr){2-3} \cmidrule(lr){4-4} \cmidrule(lr){5-5}" "\cmidrule(lr){6-7}" /// 
"& (1) & (2) & (3) & (4) & (5) & (6)  \\ \midrule") nonumbers se(%9.3f) ///
mgroups("Year 1" "Year 2" "Year 3", pattern(1 0 0 0 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) mlabels(none) ///
booktabs nonotes replace

